package sctu.edu.java.year2016.team01.lishuai.day20160606.chapter11_3;

/**
 * Created by 李大帅 on 2016/6/6.
 */
import java.util.Scanner;
public class Computer {
    public int n;
    public void commondivisor(int num1,int num2) throws MyException {
        this.n = num1<num2?num1:num2;

        if(num1<0||num2<0)
        {
            throw new MyException("您输入的数为负数，请重新输入");
        }
        while (n-->=1)
        {
            if(num1%n==0&&num2%n==0)
                break;
        }

    }

    public int getN()
    {
        return n;
    }

    public static void main(String[] args) throws MyException {

        Computer computer = new Computer();

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入第一个数：");
        int a = scan.nextInt();
        System.out.println("请输入第二个数：");
        int b = scan.nextInt();
        computer.commondivisor(a,b);
        System.out.println("最大公约数为：");
        System.out.println(computer.getN());
    }
}
